var core = require('core');
var db = core.db;
var send = core.send;

var location = function(req, res, next) {
    var body = req.body;
    var query = {
        openid : body.openid
    };
    if(body.openid)
        delete body.openid;
    var update = {
        $push : {location: body}
    };
    var options = {
        upsert : true
    };

    var SEND;
    db.schema.User.update(query, update, options, function(err, docs){
        if(err){
            SEND = new send(100002);
            res.send(SEND);
        }else{
            if(docs.nModified){
                SEND = new send(0);
                SEND.docs = docs;
                res.send(SEND);
            }
        };
    });
};

module.exports = location;
